import grails.test.GrailsUnitTestCase
import grails.test.MockUtils

class TradesPersonTests extends GrailsUnitTestCase {

    public void testNullableConstraints() {
        // Mock the validate() method.
        registerMetaClass(TradesPerson)
        MockUtils.prepareForConstraintsTests(TradesPerson)

        def testInstance = new TradesPerson()
        def errors = testInstance.validate()
        assertEquals 3, errors.size()
        assertEquals "nullable", errors["personalName"]
        assertEquals "nullable", errors["businessName"]
        assertEquals "nullable", errors["headline"]
    }

    public void testBlankConstraints(){
        // Mock the validate() method.
        registerMetaClass(TradesPerson)
        MockUtils.prepareForConstraintsTests(TradesPerson)

        def testInstance = new TradesPerson(personalName:'  ', businessName:'  ', headline:' ')
        def errors = testInstance.validate()
        assertEquals 3, errors.size()
        assertEquals "blank", errors["personalName"]
        assertEquals "blank", errors["businessName"]
        assertEquals "blank", errors["headline"]
    }
}